import { Injectable } from '@nestjs/common'
import { InjectRepository } from '@nestjs/typeorm'
import { Repository } from 'typeorm'
import { CreateInvitationDto, FindOneInvitationDto, UpdateInvitationDto } from './dto/invitation.dto'
import { Invitation } from './entities/invitation.entity'

@Injectable()
export class InvitationService {
  constructor(
    @InjectRepository(Invitation)
    private invitationRepository: Repository<Invitation>,
  ) {}

  create(data: CreateInvitationDto) {
    return this.invitationRepository.save(data)
  }

  async findAll(data: FindOneInvitationDto) {
    return await this.invitationRepository.find({
      where: data,
    })
  }

  async findOne(data: FindOneInvitationDto) {
    return await this.invitationRepository.findOneBy(data)
  }

  async update(invitationId: number, data: UpdateInvitationDto) {
    return this.invitationRepository.update(invitationId, {
      ...data,
      invitationId: undefined,
    })
  }

  delete(invitationId: number) {
    return this.invitationRepository.delete(invitationId)
  }
}
